package com.ruoyi.system.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.db.domain.system.MpCashApply;
import com.ruoyi.db.domain.system.MpClient;
import com.ruoyi.db.domain.web.MpClientTransfer;
import com.ruoyi.db.domain.web.MpIncomeRecord;
import com.ruoyi.db.mapper.system.MpCashApplyMapper;
import com.ruoyi.db.mapper.system.MpClientMapper;
import com.ruoyi.db.mapper.web.MpIncomeRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.service.IMpIncomeRecordService;

import javax.transaction.Transactional;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-07-26
 */
@Service
@Transactional(rollbackOn = Exception.class)
public class MpIncomeRecordServiceImpl implements IMpIncomeRecordService 
{
    @Autowired
    private MpIncomeRecordMapper mpIncomeRecordMapper;
    @Autowired
    private MpClientMapper mpClientMapper;
    @Autowired
    private MpCashApplyMapper mpCashApplyMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public MpIncomeRecord selectMpIncomeRecordById(Long id)
    {
        return mpIncomeRecordMapper.selectMpIncomeRecordById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param mpIncomeRecord 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<MpIncomeRecord> selectMpIncomeRecordList(MpIncomeRecord mpIncomeRecord)
    {
        return mpIncomeRecordMapper.selectMpIncomeRecordListPc(mpIncomeRecord);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param mpIncomeRecord 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertMpIncomeRecord(MpIncomeRecord mpIncomeRecord)
    {
        mpIncomeRecord.setCreateTime(DateUtils.getNowDate());
        return mpIncomeRecordMapper.insertMpIncomeRecord(mpIncomeRecord);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param mpIncomeRecord 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateMpIncomeRecord(MpIncomeRecord mpIncomeRecord)
    {
        return mpIncomeRecordMapper.updateMpIncomeRecord(mpIncomeRecord);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteMpIncomeRecordByIds(Long[] ids)
    {
        return mpIncomeRecordMapper.deleteMpIncomeRecordByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteMpIncomeRecordById(Long id)
    {
        return mpIncomeRecordMapper.deleteMpIncomeRecordById(id);
    }

    @Override
    public Map<String, Object> getFundCount() {
        //获取h5所有用户
        Map<String,Object> map = new HashMap<>();
        List<MpClient> clients = mpClientMapper.selectMpClientList(new MpClient());
        BigDecimal goldSum = clients.stream().filter(e->e.getGoldBeanBalance()!=null).collect(Collectors.toList()).stream().map( MpClient::getGoldBeanBalance).reduce(BigDecimal.ZERO, BigDecimal::add); //BigDecimal类型
        map.put("gold",goldSum);
        BigDecimal silverSum = clients.stream().filter(e->e.getSilverBeanBalance()!=null).collect(Collectors.toList()).stream().map( MpClient::getSilverBeanBalance).reduce(BigDecimal.ZERO, BigDecimal::add); //BigDecimal类型
        map.put("silver",silverSum);
        return map;
    }

}
